package com.lmx.repoDomain.tmodel;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiLookupIncludeAutomatically;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 风险记录模板
 *
 * @author ytche
 * @date 2017年8月2日
 *
 */
@Entity
@Table(name = "TNB_RISK_RECORD_MODEL")
@JsonApiResource(type = "riskRecordModel")
public class RiskRecordModel extends BaseEntity {
	private static final long serialVersionUID = 1L;
	private String name;
	private String remark;
	private Set<RiskRecordField> Fields;
	private RiskAssessModel riskModel;

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH, mappedBy = "model")
	@Fetch(FetchMode.JOIN)
	@JsonApiToMany
	@JsonApiIncludeByDefault
	public Set<RiskRecordField> getFields() {
		return Fields;
	}

	public void setFields(Set<RiskRecordField> fields) {
		Fields = fields;
	}

	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JsonApiToOne
	@JsonApiLookupIncludeAutomatically
	@JoinColumn(name = "risk_model_id")
	public RiskAssessModel getRiskModel() {
		return riskModel;
	}

	public void setRiskModel(RiskAssessModel riskModel) {
		this.riskModel = riskModel;
	}

}
